package com.english_test_sys.mapper;

import com.english_test_sys.pojo.UserRanking;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RankingMapper {

    // 修改1：统一使用users表，优化查询条件
    @Select({
            "SELECT id, username, email, user_type as userType, COALESCE(score, 0) as score",
            "FROM users",
            "WHERE (#{userType} = 'all' OR user_type = #{userType})",
            "ORDER BY score DESC",
            "LIMIT 100"
    })
    List<UserRanking> getRankingList(@Param("userType") String userType);

    // 修改2：修正表名并添加相同过滤条件
    @Select({
            "SELECT COUNT(*) FROM users",
            "WHERE (#{userType} = 'all' OR user_type = #{userType})"
    })
    Integer getTotalUsers(@Param("userType") String userType);
}